package com.utility.result;


import java.io.Serializable;

/**
 *  统一返回状态
 * @author hw
 */
public class Result<T> implements Serializable {
	private static final long serialVersionUID = 2405172041950251807L;
	/**
	 * //返回状态码
	 */
	private int code;
	/**
	 *  返回的描述
	 */
	private Object msg;
	/**
	 * 返回的数据
	 */
	private T  data;

	/**
	 * 构造方法-1
	 * @param code 状态码
	 * @param data 数据集合
	 * @param msg 状态描述
	 */
	public Result(int code, Object msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public Result(T data){
		this.code = 200;
		this.data = data;
	}

	public Result(){}

	/**
	 * 构造方法-2
	 * @param code 状态码
	 * @param msg 状态描述
	 */
	public Result(int code, Object msg) {
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 	自定义返回类型
	  * @param result 状态码
	 * @param data 数据集合
	 * @return result:200 data:[] ResultCode:请求成功  2018-12-12 11:45:20
	 */
	public static <T> Result<T> returnCode(int result,Object msg,T data) {
		return new Result(result,msg,data);

	}
	/**
	 * 	自定义返回类型
	  * @param code 状态码
	 * @return result:200  ResultCode:请求成功  2018-12-12 11:45:20
	 */
	public static <T> Result<T> returnCode(int code,Object msg) {
		return new <T> Result(code,msg);
	}

	/**
	 * 	 已生成成功类型
	 * @return result:200,  ResultCode:请求成功,  2018-12-12 11:45:20
	 */
	public static <T> Result<T> returnCodeSuccess() {
		return new <T> Result(200,"请求成功");
	}
	/**
	 * 	 已生成失败类型
	 * @return result:200,  ResultCode:请求失败,  2018-12-12 11:45:20
	 */
	public static <T> Result<T> returnCodeError() {
		return new <T> Result<T>(-1,"请求失败");
	}




	/**
	 *  已生成成功类型
	 * @param data 数据集合
	 * @return result:200, data:[], ResultCode:请求成功,  2018-12-12 11:45:20
	 */
	public static  <T> Result<T> returnCodeSuccess(T data) {
		return new <T> Result<T>(200,"请求成功",data);
	}
	/**
	 *  已生成失败类型
	 * @param data 数据集合
	 * @return result:200, data:[], ResultCode:请求失败,  2018-12-12 11:45:20
	 */
	public static  <T> Result<T> returnCodeError(Object data) {
		return new <T> Result<T>(-1,data);
	}


	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getMsg() {
		return msg;
	}

	public void setMsg(Object msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
